import constant from "plugins/constant.js"
let caches = {
	token: {
		get: function() {
			return localStorage.getItem(constant.cacheskey.jwttoken);
		},
		set: function(token) {
			localStorage.setItem(constant.cacheskey.jwttoken, token);
		},
		remove: function() {
			localStorage.removeItem(constant.cacheskey.jwttoken);
		}
	},
	user: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.user) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.user)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.user, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.user);
		}
	},
	menus: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.menus) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.menus)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.menus, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.menus);
		}
	},
	setting: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.systemSetting) ? JSON.parse(sessionStorage.getItem(constant.cacheskey
					.systemSetting)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.systemSetting, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.systemSetting);
		}
	},
	codes: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.codes) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.codes)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.codes, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.codes);
		}
	},
	cleanCaches: function() {
		caches.user.remove();
		caches.menus.remove();
		caches.codes.remove();
		caches.setting.remove();
	},
	cleanAll: function() {
		caches.user.remove();
		caches.menus.remove();
		caches.codes.remove();
		caches.token.remove();
	}
}

export default caches;
